﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Theoreme.Library
{
    public static class ExtensionOfControl
    {
        /// <summary>
        /// Returns whether the function is being executed during design time in Visual Studio.
        /// </summary>
        public static bool IsDesignTime(this Control control)
        {
            if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
            {
                return true;
            }

            if (control.Site != null && control.Site.DesignMode)
            {
                return true;
            }

            var parent = control.Parent;
            while (parent != null)
            {
                if (parent.Site != null && parent.Site.DesignMode)
                {
                    return true;
                }
                parent = parent.Parent;
            }
            return false;
        }

    }
}
